<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">房价名称</td>
                    <td><input type="text" v-model="queryinfo.PlanName"/></td>
                </tr>
                <tr>
                    <td align="right">门店名称</td>
                    <td>
                        <select v-model="queryinfo.ShopId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in data.listshop">{{ item.ShopName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">房型名称</td>
                    <td>
                        <select v-model="queryinfo.HouseTypeId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in data.list">{{ item.HouseTypeName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">房型价格</td>
                    <td><input type="text" v-model="queryinfo.Price"/></td>
                </tr>
                <tr>
                    <td align="right">数量</td>
                    <td><input type="text" v-model="queryinfo.Count"/></td>
                </tr>
                <tr>
                    <td align="right">状态</td>
                    <td>
                        <input type="radio" :value="0" name="state" v-model="queryinfo.State"/>禁用
                        <input type="radio" :value="1" name="state" v-model="queryinfo.State"/>启用
                    </td>
                </tr>
                <tr>
                    <td align="right">早餐数量</td>
                    <td><input type="text" v-model="queryinfo.BreakFastCount"/></td>
                </tr>
                <tr>
                    <td align="right">开始时间</td>
                    <td><input type="date" v-model="queryinfo.BeginTime"/></td>
                </tr>
                <tr>
                    <td align="right">结束时间</td>
                    <td><input type="date" v-model="queryinfo.EndTime"/></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" class="btn btn-primary" @click="add"/></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive, onMounted}from 'vue';
import axios from 'axios';
import moment from 'moment';
import {useRouter,useRoute}from 'vue-router'
const router=useRouter();
const route=useRoute();

let queryinfo=reactive({
  "PlanName": "",
  "ShopId": '',
  "HouseTypeId": '',
  "Price": '',
  "Count": '',
  "State": 0,
  "BreakFastCount": '',
  "BeginTime": "",
  "EndTime": "",
})

let data:any=reactive({
    listshop:[],
    list:[]
})

onMounted(()=>{
    getshoplist();
    gethousedist();
})

const gethousedist=()=>{
    axios({
        url:'/api/House/GetHouseList',
        method:'get',
        params:{pagesize:100}
    })
    .then(res=>{
        console.log(res);
        data.list=res.data.list;
    })
    .catch(err=>{
        console.log(err);
    })
}

const getshoplist=()=>{
    axios({
        url:'/api/Shop/Getshop',
        method:'get',
        params:{pagesize:100}
    })
    .then(res=>{
        console.log(res);
        data.listshop=res.data.c
    })
    .catch(err=>{
        console.log(err);
    })
}


const add=()=>{
    axios({
        url:'/api/House/AddHousePrice',
        method:'post',
        data:queryinfo,
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert('房价名称已存在');
            return;
        }
        if(res.data>0){
            alert('添加成功');
            router.push('/housepricelist')
        }
        else{
            alert('添加失败');
        }
    })
    .catch(err=>{
        console.log(err);
    })
}





</script>

<style scoped>

</style>